package com.woniuxy.thred.syn;

/**
 * description: UnsafeTest02 <br>
 * date: 2022/2/6 12:09 上午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 操作容器
 */
public class SynBlockTest02 {
    public static void main(String[] args) throws InterruptedException {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                //同步块
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }
        Thread.sleep(1000);
        System.out.println(list.size());
    }
}


